package com.klamerek.rainbow.client.charts.geom;

import java.util.List;

/**
 * A basic point class
 *
 */
public class MyPoint {

	/**
	 * X-axis.
	 */
	private double x ;

	/**
	 * Y-axis.
	 */
	private double y ;

	/**
	 * Constructor
	 * @param x X-axis.
	 * @param y Y-axis.
	 */
	public MyPoint (double x, double y){
		this.x = x ; 
		this.y = y ; 
	}

	/**
	 * 
	 * @return
	 */
	public double getX() {
		return x;
	}

	/**
	 * 
	 * @param x
	 */
	public void setX(double x) {
		this.x = x;
	}

	/**
	 * 
	 * @return
	 */
	public double getY() {
		return y;
	}

	/**
	 * 
	 * @param y
	 */
	public void setY(double y) {
		this.y = y;
	}

	/**
	 * Get the middle point between a and b.
	 * @param a The first point. 
	 * @param b The second point.
	 * @return The middle point.
	 */
	public static MyPoint getMiddle (MyPoint a, MyPoint b){
		MyPoint result = new MyPoint((a.x + b.x) / 2.0,(a.y + b.y) / 2.0);
		return result;
	}

	/**
	 * Get the symmetric point 
	 * @param a Origin point.
	 * @param c Center point.
	 * @return The symmetric point.
	 */
	public static MyPoint getSymmetric (MyPoint a, MyPoint c){
		MyPoint result = new MyPoint(2.0 * c.x - a.x,2.0 * c.y - a.y);
		return result;
	}

	/**
	 * Get the distance between a and b.
	 * @param a First point.
	 * @param b Second point.
	 * @return The distance.
	 */
	public static double getDistance (MyPoint a,MyPoint b){
		double dx = b.x - a.x ; 
		double dy = b.y - a.y ;
		return Math.sqrt(dx * dx + dy * dy) ;
	}

	/**
	 * Test if the point is near the current point.
	 * @param x
	 * @param y
	 * @param delta 
	 * @return True is the parameter point is near the current point.
	 */
	public boolean isNearZone (int x, int y, double delta){
		return ((x >=  this.x - delta) && (x <= this.x + delta) 
				&& (y >= this.y - delta) && (y <= this.y + delta)) ; 
	}

	/**
	 * Test if the point is near the current point.
	 * @param point
	 * @param delta
	 * @return True is the parameter point is near the current point.
	 */
	public boolean isNearZone(MyPoint point, double delta){
		return ((point.x >=  this.x - delta) && (point.x <= this.x + delta) 
				&& (point.y >= this.y - delta) && (point.y <= this.y + delta)) ; 
	}

	/**
	 * Test if the list contains the point.
	 * @param listPoint
	 * @param point
	 * @param delta
	 * @return
	 */
	public static boolean ListContains(List<MyPoint> listPoint, MyPoint point, double delta){
		boolean result = false;
		if (point != null){
			for(MyPoint p : listPoint){
				if (point.isNearZone(p, delta)){
					result = true;
					break;
				}
			}
		}
		return result;
	}

}
